﻿import com.dinmax.isolution.*
import com.dinmax.flash.utilities.xml.*;

class ParseXMLTheme
{
	
	public static function parse(node:XMLNode):Array {
		var response:Array=new Array();
		var nodes:Array=XMLUtils.getNodes(node,"theme");
		for (var i:Number=0;i<nodes.length;i++) {
			var theme:Theme=new Theme();
			theme.setId(XMLUtils.getAttribute(nodes[i],"id"));
			theme.setName(XMLUtils.getAttribute(nodes[i],"name"));
			theme.setIndex(XMLUtils.getAttribute(nodes[i],"index"));
			theme.setIcon(XMLUtils.getAttribute(nodes[i],"icon"));
			theme.setFavorite((XMLUtils.getAttribute(nodes[i],"favorite") == "true"));
			response.push(theme);
		}
		//trace("ParseXMLTheme | parse | response= "+response)
		return response;
	}
	
	
	public static function parseChange(node:XMLNode):Array {
		var response:Array=new Array();
		var theme:Theme = new Theme();
		theme.setId(XMLUtils.getAttribute(node, "id"));
		theme.setName(XMLUtils.getAttribute(node, "themeName"));
		theme.setIcon(XMLUtils.getAttribute(node, "icon"));
		theme.setFavorite((XMLUtils.getAttribute(node,"favorite") == "true"));
		response.push(theme);
		return response;
	}
	
	public static function parseTheme(node:XMLNode):Array {
		
		var response:Array=new Array();
		var nodes:Array=XMLUtils.getNodes(node,"command");
		for (var i:Number=0;i<nodes.length;i++) {
			var command:Command=new Command();
			command.setState(XMLUtils.getAttribute(nodes[i],"state"));
			command.setDevice(XMLUtils.getAttribute(nodes[i],"artifact"));
			response.push(command);
		}
		return response;
	}
	
}